<?php
/**
 * Created by novebeta.
 * Date: 2/5/13
 * Time: 5:33 AM
 */
class SearchController extends FrontEndController
{
    private $_indexFiles = 'runtime.search';
    public $layout='//layouts/dalam';
    /**
     * (non-PHPdoc)
     * @see CController::init()
     */
    public function init(){
        Yii::import('application.vendors.*');
        require_once('Zend/Search/Lucene.php');
        parent::init();
    }

    public function actionCreate()
    {
        u::build_index();
        echo 'Lucene index created';
    }

    public function actionSearch()
    {
        //$this->layout='column2';
        if (($term = Yii::app()->getRequest()->getParam('q', null)) !== null) {
            $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles));
            $results = $index->find($term);
            $query = Zend_Search_Lucene_Search_QueryParser::parse($term);

            $this->render('search', compact('results', 'term', 'query'));
        }
    }
}
